package pnu.ssm.ga;

public class Population {
	Individual individuals[];
	
	public Population(int populationSize, boolean initialise) {
		individuals = new Individual[populationSize];
		if(initialise){
			for(int i=0; i<size(); i++){
				Individual newIndividual = new Individual();
				newIndividual.generateIndividual();
				saveIndividual(i, newIndividual);
			}
		}
	}
	
	public Individual getIndividual(int index){
		return individuals[index];
	}
	
	// 여기서 Fitness 는 총 공차거리를 의미하기 때문에
	// 작을 수록 좋은 것이다.
	// 그러므로 가장 최소의 Fitness를 리턴해야한다.
	public Individual getFittestIndividual(){
		Individual fittest = individuals[0];
		for(int i=0; i<size(); i++){
			if(fittest.getFitness() >= getIndividual(i).getFitness()){
				fittest = getIndividual(i);
			}
		}
		return fittest;
	}	
	
	public int size(){
		return individuals.length;
	}
	
	public void saveIndividual(int index, Individual indiv){
		individuals[index] = indiv;
	}
}







